using System.Collections.Generic;
using FireStarter.Base;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using FireStarter.CodeGeneration.Parser;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Templates.UsingControlManager
{
    [TestFixture]
    public class Test_UI_GridControl_UsingControlManager : TestBase
    {
        //TODO: what if a null DMClass is passed through?

        [Ignore("TODO: fix the template names")]
        [Test]
        public void Test_OneBusinessObjectOneProperty()
        {
            //---------------Set up test pack-------------------
            string expectedTemplate =
                @"using System.Collections.Generic;
using Habanero.BO;
using Habanero.Faces.Base;
using TestProject.BO;

namespace TestProject.UI
{
    public class TestClassesGridControl : ControlManager
    {
        private IReadOnlyGridControl _readOnlyGridControl;

        public TestClassesGridControl(IControlFactory controlFactory) : base(controlFactory)
        {
        }

        protected override void InitialiseControl()
        {
            SetupGrid();
            AddGridFilters();
            LoadCollection();
        }

        private void SetupGrid()
        {
            _readOnlyGridControl = _controlFactory.CreateReadOnlyGridControl();
            BorderLayoutManager manager = _controlFactory.CreateBorderLayoutManager(_control);
            manager.AddControl(_readOnlyGridControl, BorderLayoutManager.Position.Centre);
        }

        private void AddGridFilters()
        {
            _readOnlyGridControl.FilterControl.Visible = false;
            //TODO: Add the filters you want and remove the above line
        }

        private void LoadCollection()
        {
            BusinessObjectCollection<TestClass> testClasses = new BusinessObjectCollection<TestClass>();
            testClasses.LoadAll();
            _readOnlyGridControl.SetBusinessObjectCollection(testClasses);
        }
    }
}";

            string template = FireStarter.CodeGeneration.Templates.UI_GridControl_UsingControlManager;

            IModelClass dmClass = new DMClass();
            dmClass.ClassName = "TestClass";
 
            StatementParser statementParser = new StatementParser();
            IModelSolution modelSolution = new DMSolution();
            modelSolution.BOProjectName = "TestProject.BO";
            modelSolution.UIProjectName = "TestProject.UI";

            DMAssembly dmAssembly = new DMAssembly();
            dmAssembly.Solution = (DMSolution)modelSolution;
            ((DMClass)dmClass).Assembly = dmAssembly;

            ModelStrategyMapper modelStrategyMapper = new ModelStrategyMapper();
            modelStrategyMapper.SetStrategy(typeof(IModelElement), new ReflectionGenerationStrategy());
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            TemplateExpression templateExpression = statementParser.Parse(ref template);
            string generatedTemplate = templateExpression.Generate(modelStrategyMapper, dmClass);
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTemplate, generatedTemplate);
        }
    }
}